<?php

namespace app\rent\controller;

use think\Controller;

class Index extends Controller
{
    protected $ProductModel = null;

    protected $CategoryModel = null;

    public function _initialize()
    {
        $this->ProductModel = model('Product.Product');
        $this->CategoryModel = model('Category');
    }

    public function index()
    {
        // 顶部轮播 新品
        $NewProductData = $this->ProductModel->where(['flag' => ['=', 1], 'rentstatus' => ['<>', 1], 'status' => ['=', 1]])->order('createtime DESC')->limit(5)->select();

        // 中间带查看详情的轮播 推荐
        $ProductData = $this->ProductModel->where(['flag' => ['=', 3], 'rentstatus' => ['<>', 1], 'status' => ['=', 1]])->order('createtime DESC')->limit(5)->select();

        // 文章的 type != page flag => index
        $CategoryData = $this->CategoryModel->order('createtime DESC')->select();

        $this->success('查询成功', null, [
            'NewProductData' => $NewProductData,
            'ProductData' => $ProductData,
            'CategoryData' => $CategoryData
        ]);
    }
}
